package com.tcat.item.mapper;

import com.tcat.item.pojo.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Author liysh
 * @Date 2020/12/11
 */
public interface CategoryMapper extends Mapper<Category>, SelectByIdListMapper<Category,Long> {
    /**
     * 根据品牌id查询商品分类
     * @param bid
     * @return
     */
    @Select("SELECT * FROM tb_category WHERE id IN(SELECT category_id FROM tb_category_brand Where brand_id = #{bid})")
    List<Category> queryByBrandId(@Param("bid") Long bid);

    /**
     * 根据category id 删除中间表相关数据
     * @param cid
     */
    @Delete("DELETE FROM tb_category_brand Where category_id=#{cid}")
    void deleteByCategoryIdInCategoryBrand(@Param("cid") Long cid);

    /**
     * 查询最后一条数据
     * @return
     */
    @Select("SELECT * FROM tb_category WHERE id=(SELECT MAX(id) FROM tb_category)")
    List<Category> selectList();

}
